﻿package net.wangit.dev.unit;

import net.wangit.MapList;
import net.wangit.context.LocalContext;
import net.wangit.dev.ConsoleDomainUtil;
import net.wangit.jdbc.DB;
import net.wangit.jdbc.util.DBHelper;
import net.wangit.support.MapListFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class TableMapListFactory implements MapListFactory {

	private static final Log log = LogFactory
			.getLog(net.wangit.dev.unit.TableMapListFactory.class);
	private static final String SQL = "select t as value,t+' - '+tl as name from TABLE order by t";

	public TableMapListFactory() {
	}

	public MapList getMapList() {
		try {
			MapList list;
			net.wangit.context.ActionContext ac = LocalContext
					.getLocalContext().getActionContext();
			String domain = ConsoleDomainUtil.getDomain(ac);
			DB db = DBHelper.getDomainDB(domain);
			list = db.query(TableMapListFactory.SQL);
			return list;
		} catch (Exception e) {
			log.error((new StringBuilder("create Enumeration failed:")).append(
					e).toString());
			return null;
		}
	}

}
